import { request } from "@/utils/service"
import type * as Notice from "./types/notice"

/** 分页查询公告列表 */
export function getNoticeListApi(params: Notice.NoticeQueryParam) {
  return request<Notice.NoticeListResponse>({
    url: "/notice/list",
    method: "get",
    params
  })
}

/** 获取公告详情 */
export function getNoticeDetailApi(noticeId: number) {
  return request<Notice.NoticeDetailResponse>({
    url: `/notice/${noticeId}`,
    method: "get"
  })
}

/** 创建公告 */
export function createNoticeApi(data: Notice.CreateNoticeRequest) {
  return request<Notice.CreateNoticeResponse>({
    url: "/notice",
    method: "post",
    data
  })
}

/** 更新公告 */
export function updateNoticeApi(data: Notice.UpdateNoticeRequest) {
  return request<Notice.UpdateNoticeResponse>({
    url: "/notice",
    method: "put",
    data
  })
}

/** 删除公告 */
export function deleteNoticeApi(noticeId: number) {
  return request<Notice.DeleteNoticeResponse>({
    url: `/notice/${noticeId}`,
    method: "delete"
  })
}

/** 批量删除公告 */
export function batchDeleteNoticeApi(noticeIds: number[]) {
  return request<Notice.BatchDeleteNoticeResponse>({
    url: "/notice/batch",
    method: "delete",
    data: noticeIds
  })
}

/** 更新公告状态 */
export function updateNoticeStatusApi(noticeId: number, status: number) {
  return request<Notice.UpdateNoticeStatusResponse>({
    url: `/notice/${noticeId}/status/${status}`,
    method: "put"
  })
}

/** 更新公告置顶状态 */
export function updateNoticeTopApi(noticeId: number, isTop: number) {
  return request<Notice.UpdateNoticeTopResponse>({
    url: `/notice/${noticeId}/top/${isTop}`,
    method: "put"
  })
}